<UserControl x:Class="Microsoft.Robotics.Navigation.Visualization.GlobalMapView" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:v="clr-namespace:Microsoft.Robotics.Visualization;assembly=Microsoft.Robotics.Visualization" 
             xmlns:r="clr-namespace:Microsoft.Robotics.Navigation.Visualization"
             mc:Ignorable="d" 
             d:DesignHeight="800" d:DesignWidth="800">
    <UserControl.Resources>
        <r:ParticleValueConverter x:Key="ParticleValueConverter" />
        <r:OriginValueConverter x:Key="OriginValueConverter" />
        <r:RobotPathValueConverter x:Key="RobotPathValueConverter"/>
    </UserControl.Resources>

    <DockPanel x:Name="parentDock">
        <StackPanel Orientation="Horizontal"  DockPanel.Dock="Top">
            <TextBlock VerticalAlignment="Center" Text="{Binding Path=MinDistanceToSurface, StringFormat=minS: {0:N4}}"  Width="70"/>
            <TextBlock VerticalAlignment="Center" Text="{Binding Path=MaxDistanceToSurface, StringFormat=maxS: {0:N4}}"  Width="70"/>
            <TextBlock VerticalAlignment="Center" Text="{Binding Path=Dispersion, StringFormat=d: {0:N4}}"  Width="70"/>
            <TextBlock VerticalAlignment="Center" Text="{Binding ElementName=particleSlider, Path=Value, StringFormat=Particle: {0}}" Width="70"/>
            <Slider x:Name="particleSlider" ToolTip="Select the visible particle." Value="{Binding Path=SelectedParticleId}" Minimum="1" Maximum="{Binding Path=ParticleDetails.Count}" SmallChange="1" Width="150"/>
            <TextBlock VerticalAlignment="Center" Text="{Binding Path=SelectedParticleWeight, StringFormat=Weight: {0:N4}}" Width="100"/>
            <TextBlock VerticalAlignment="Center" Text="{Binding Path=SelectedParticleSingleIterationWeight, StringFormat=Fitness: {0:N4}}" Width="100"/>
            <TextBlock VerticalAlignment="Center" Text="{Binding Path=SelectedParticleAge, StringFormat=Age: {0:N0}}" Width="50"/>
            <TextBlock VerticalAlignment="Center" Text="{Binding Path=SelectedParticlePose.X, StringFormat=X: {0:N1}}" Width="50"/>
            <TextBlock VerticalAlignment="Center" Text="{Binding Path=SelectedParticlePose.Y, StringFormat=Y: {0:N1}}" Width="50"/>
            <TextBlock VerticalAlignment="Center" Text="{Binding Path=SelectedParticlePose.Heading, StringFormat=H: {0:N4}}" Width="75"/>
            <CheckBox IsChecked="{Binding Path=IsHdpHidden}" Width="100">Hide HDP</CheckBox>
            <CheckBox IsChecked="{Binding Path=ShowAllReadings}" Width="140">Show all readings</CheckBox>
            <Slider x:Name="uiScaleSlider" ToolTip="Determines the UI scale factor." Value="1" Minimum="0.1" Maximum="2" Width="50" Visibility="Hidden"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal"  DockPanel.Dock="Top">
            <TextBlock VerticalAlignment="Center" Text="{Binding Path=MapCoordinates}"  Width="800"/>
        </StackPanel>
        <ScrollViewer x:Name="zoomable" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" DockPanel.Dock="Top" PreviewMouseLeftButtonDown="OnMouseDown" MouseLeftButtonUp="OnMouseUp" MouseMove="OnMouseMove">
                <DockPanel RenderTransformOrigin="0, 0" HorizontalAlignment="Left" VerticalAlignment="top" Margin="0,0,0,0" Width="{Binding Path=GlobalMapWidth}" Height="{Binding Path=GlobalMapHeight}" >
                    <DockPanel.LayoutTransform>
                        <ScaleTransform ScaleX="{Binding ElementName=uiScaleSlider,Path=Value}" ScaleY="{Binding ElementName=uiScaleSlider,Path=Value}"></ScaleTransform>
                    </DockPanel.LayoutTransform>
                <Canvas RenderTransformOrigin="0.5, 0.5">
                    <Canvas.RenderTransform>
                        <ScaleTransform ScaleX="-1" ScaleY="-1"></ScaleTransform>
                    </Canvas.RenderTransform>
                    <v:VideoStreamControl x:Name="globalMap" Margin="0,0,0,0"  Frame="{Binding Path=GlobalMapVideoFrame}" />
                    <StackPanel RenderTransformOrigin="0.5, 0" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,0" Canvas.Left="{Binding Path=SurfaceX}" Canvas.Top="{Binding Path=SurfaceY}">
                        <StackPanel.RenderTransform>
                            <TransformGroup>
                                <RotateTransform Angle="{Binding Path=SurfaceAngle}"/>
                            </TransformGroup>
                        </StackPanel.RenderTransform>
                        <v:VideoStreamControl x:Name="surface" Margin="0,0,0,0"  Frame="{Binding Path=SurfaceModel.VideoFrame}"/>
                    </StackPanel>
                    <StackPanel RenderTransformOrigin="0.5, 0" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,0" Canvas.Left="{Binding Path=HdpX}" Canvas.Top="{Binding Path=HdpY}" Visibility="{Binding Path=HdpVisibility}">
                        <StackPanel.RenderTransform>
                            <TransformGroup>
                                <RotateTransform Angle="{Binding Path=HdpAngle}"/>
                            </TransformGroup>
                        </StackPanel.RenderTransform>
                        <v:VideoStreamControl x:Name="localMap" Margin="0,0,0,0"  Frame="{Binding Path=HdpModel.VideoFrame}"/>
                    </StackPanel>
                    <!-- The following should probably change to a GeometryDrawing for perf reasons. 
                        See this example: 
                        http://msdn.microsoft.com/query/dev11.query?appId=Dev11IDEF1&l=EN-US&k=k(System.Windows.Media.EllipseGeometry);k(VS.XamlEditor);k(SolutionItemsProject);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5)&rd=true 
                    -->
                    <!--<Path Stroke="Black" StrokeThickness="3" Data="{Binding Path=Origin, Converter={StaticResource OriginValueConverter}}"/>-->
                    <Path Stroke="Green" StrokeThickness="2" Data="{Binding Path=RobotPath, Converter={StaticResource RobotPathValueConverter}}"/>
                    <Path Stroke="Blue" StrokeThickness="1" Data="{Binding Path=ParticlePoses, Converter={StaticResource ParticleValueConverter}}"/>
                    <Path Stroke="{Binding Path=RobotColor}" StrokeThickness="2">
                        <Path.Data>
                            <GeometryGroup>
                                <EllipseGeometry Center="{Binding Path=RobotCenter}" RadiusX="{Binding RadiusX}" RadiusY="{Binding RadiusY}" />
                                <LineGeometry StartPoint="{Binding Path=RobotCenter}" EndPoint="{Binding Path=RobotEnd}"/>
                            </GeometryGroup>
                        </Path.Data>
                    </Path>                    
                </Canvas>
            </DockPanel>
            </ScrollViewer>
    </DockPanel>
</UserControl>
